using System.Configuration;

namespace WIT.Global;

/// <summary>
/// web/app.config帮助类
/// </summary>
public class ConfigHelper
{
	private static string _connectionString;

	/// <summary>
	/// ConnectionString
	/// </summary>
	public static string ConnectionString
	{
		get
		{
			if (string.IsNullOrEmpty(_connectionString))
			{
				_connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"]?.ConnectionString;
			}
			return _connectionString;
		}
	}

	/// <summary>
	/// GetAppSettingValue
	/// </summary>
	/// <param name="key"></param>
	/// <returns></returns>
	public static string GetAppSetting(string key)
	{
		string text = ConfigurationManager.AppSettings[key];
		if (text == null)
		{
			return string.Empty;
		}
		return text.ToString();
	}

	/// <summary>
	/// 获取ConnectionString
	/// </summary>
	/// <param name="name">ConnectionString的Name属性值</param>
	/// <returns></returns>
	public static string GetConnectionString(string name = "ConnectionString")
	{
		return ConfigurationManager.ConnectionStrings[name]?.ConnectionString;
	}
}
